package com.coke.spring.security.token;

import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author cwm
 * @Description 自定义ip登录方式认证信息实体类
 * @date 2021/8/26 上午11:53
 * @Version 1.0
 */
public class IpAuthenticationToken extends AbstractAuthenticationToken {

    @Getter
    @Setter
    private String ip;

    //构造方法是认证时使用的
    public IpAuthenticationToken(String ip) {
        super(null);
        this.ip = ip;
        super.setAuthenticated(false);
    }

    //构造方法是认证成功后使用的
    public IpAuthenticationToken(String ip, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.ip = ip;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.ip;
    }
}
